package com.wyh.rabbitmq.ttlorder.listener;

import com.rabbitmq.client.Channel;
import com.wyh.rabbitmq.ttlorder.model.Order;
import com.wyh.rabbitmq.ttlorder.model.OrderDetail;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * @author wuyuhan
 * @date 2021/4/10 11:56
 */
@Component
public class MyOrderListener {

    @RabbitListener(queues = "q.order",ackMode = "MANUAL")
    public void onMessage(Order order, Channel channel, Message message) throws IOException {
        System.out.println("写入数据库");
        System.out.println(order);

        for (OrderDetail detail : order.getDetails()) {
            System.out.println(detail);
        }

        channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
    }
}
